function h=drawinfo(info,varargin)
% drawinfo: Draw an information box
%
% SYNTAX:
%   h = drawinfo(info,'prop1',value1,...)
%   Return handles of graphics objects representing the information box.
%   Information box object info should be created with function NEWINFO.
%   Available properties and default values can be seen by typing the following command:
%           newinfo('')
%   
% See also NEWINFO

%   Author: Hongbin Ma
%   Last updated: 2009-6-2 with MATLAB 6.5
%   Problems or suggestions? Email me: mathmhb[at]163.com

h=[];
if isempty(info)|isempty(info.String),
    return;
end;
pos=[varargin{:}];
if isempty(pos),
    pos=info.Position;
end;
if isempty(pos),
    ax=axis;
    if length(ax)==6,
        pos=[(ax(1)+ax(2))*0.5,(ax(3)+ax(4))*0.5,(ax(5)+ax(6))*0.5];
    else,
        pos=[(ax(1)+ax(2))*0.5,(ax(3)+ax(4))*0.5];
    end;
end;

x=pos(1);
y=pos(2);
if length(pos)>2,
    z=pos(3);
    h=text(x,y,z,info.String);
else;
    h=text(x,y,info.String);
end;
set(h,...
'FontName',info.FontName,...
'FontSize',info.FontSize,...
'FontAngle',info.FontAngle,...
'FontWeight',info.FontWeight,...
'Color',info.Color,...
'Rotation',info.Rotation,...
'HorizontalAlignment',info.HorizontalAlignment,...
'VerticalAlignment',info.VerticalAlignment...
);
set(h,'EdgeColor',info.EdgeColor,'BackgroundColor',info.BackgroundColor,'Margin',info.Margin);

